using IQIGame.Onigao.Game;
using IQIGame.Onigao.Logic;

namespace IQIGame.Onigao.GamePlay
{
    public class CFSMCond_Level_Logic_Monster_IsCloseToHero : CFSMConditionFunc<IQIGame.Onigao.Logic.LevelEntity, CFSMLevel_Logic_MonsterData>
    {
        protected override void OnInit()
        {

        }

        public System.Boolean GetValue()
        {
            //是否有玩家离当前实体足够近
            LevelHeroEntity heroEntity = data.lockingEntity;
            if (heroEntity != null && !heroEntity.isUndetectable)
            {
                float minDistance = 100;
                ObstacleInfo obstacle = entity.entityConfig.obstacle;
                if (obstacle != null && !obstacle.invalid)
                {
                    minDistance = obstacle.maxDisToCenter + LgLevelConst.HeroEntityRadius + LgLevelConst.InteractMaxBoundsGap;
                }
                return (heroEntity.position - entity.position).sqrMagnitude <= minDistance * minDistance;
            }
            return false;
        }

        public override bool Check()
        {
            return Compare(GetValue());
        }

        public override void OnReset()
        {
            base.OnReset();
        }
    }
}
